﻿package mortal.game.view.copy.singleTowerCopy2.item
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.copy.singleTowerCopy2.data.*;
    import mortal.mvc.core.*;

    public class SingleTowerRightPanel extends GSprite
    {
        protected var _leftBtn:GLoadedButton;
        protected var _rightBtn:GLoadedButton;
        protected var _midBg:ScaleBitmap;
        protected var _timeDes:GBitmap;
        protected var _pageSelecter:PageSelecter;
        protected var _enterBtn:GLoadingButton;
        protected var _sep:GImageBitmap;
        protected var _totalNum:BitmapNumberText;
        protected var _curNum:BitmapNumberText;
        protected var _copyList:GTileList;
        protected var _btnList:GTileList;
        private var _btnSelIndex:int = 0;
        private var _levelArr:Array;
        private var _showArr:Array;
        private var _openLen:int = 2;
        private var _selCell:SingleTowerListCell;
        private var _pageSize:int = 10;

        public function SingleTowerRightPanel()
        {
            this._levelArr = [56, 72, 91, 92];
            this._showArr = [];
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.sigleTowerCopy, this.onShow);
            return;
        }// end function

        private function onShow() : void
        {
            this._leftBtn = UIFactory.gLoadedButton(ImagesConst.MountLeft_upSkin, 0, 0, 33, 37, this);
            this._leftBtn.label = "";
            this._rightBtn = UIFactory.gLoadedButton(ImagesConst.MountRight_upSkin, 438, 0, 33, 38, this);
            this._rightBtn.label = "";
            this._midBg = UIFactory.bg(0, 39, 470, 514, this, ImagesConst.PanelBg);
            this._timeDes = UIFactory.gBitmap(ImagesConst.SigleTowerCopyTimeDes, 3, 475, this);
            this._pageSelecter = UIFactory.pageSelecter(375, 476, this, PageSelecter.SingleMode);
            this._pageSelecter.setbgStlye(ImagesConst.ComboBg, GlobalStyle.textFormatBai.center());
            this._pageSelecter.maxPage = 1;
            this._pageSelecter.pageTextBoxSize = 36;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            this._enterBtn = UIFactory.gLoadingButton(ImagesConst.tower_win_go2_upSkin, 157, 507, 157, 39, this);
            this._enterBtn.label = "";
            this._sep = UIFactory.gImageBitmap(ImagesConst.GroupCopyTxt_2, 171, 471, this);
            this._totalNum = UIFactory.bitmapNumberText(190, 474, "QuestionCopyNum.png", 18, 25, -2, this, 13, 0);
            this._totalNum.text = "3";
            this._curNum = UIFactory.bitmapNumberText(159, 474, "QuestionCopyNum.png", 18, 25, -2, this, 13, 0);
            this._curNum.text = "2";
            this._copyList = UIFactory.tileList(4, 44, 475, 430, this);
            this._copyList.direction = GBoxDirection.VERTICAL;
            this._copyList.verticalGap = 0;
            this._copyList.horizontalGap = 2;
            this._copyList.rowHeight = 86;
            this._copyList.columnWidth = 230;
            this._copyList.columnCount = 2;
            this._copyList.rowCount = 5;
            this._copyList.width = 475;
            this._copyList.setStyle("cellRenderer", SingleTowerListCell);
            this._btnList = UIFactory.tileList(49, 3, 399, 50, this);
            this._btnList.direction = GBoxDirection.VERTICAL;
            this._btnList.verticalGap = 2;
            this._btnList.horizontalGap = 2;
            this._btnList.rowHeight = 50;
            this._btnList.columnWidth = 128;
            this._btnList.columnCount = 3;
            this._btnList.rowCount = 1;
            this._btnList.width = 399;
            this._btnList.setStyle("cellRenderer", SingleTowerLvBtn);
            this.initTab();
            this.initCopysInfo();
            this._btnList.configEventListener(Event.CHANGE, this.onBtnChange);
            this._copyList.configEventListener(Event.CHANGE, this.handleCellRendererChange);
            this._enterBtn.configEventListener(MouseEvent.CLICK, this.onEnterCopy);
            var _loc_1:Boolean = false;
            this._rightBtn.enabled = false;
            this._leftBtn.enabled = _loc_1;
            var _loc_1:* = [FilterConst.colorFilter2];
            this._rightBtn.filters = [FilterConst.colorFilter2];
            this._leftBtn.filters = _loc_1;
            this.updateEnterNum();
            this.addEvs(true);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this.addEvs(false);
            LoaderHelp.removeResEvent(ResFileConst.sigleTowerCopy, this.onShow);
            this._leftBtn = null;
            this._rightBtn = null;
            this._midBg = null;
            this._timeDes = null;
            this._pageSelecter = null;
            this._enterBtn = null;
            this._sep = null;
            this._totalNum = null;
            this._curNum = null;
            this._copyList = null;
            this._btnList = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function addEvs(param1:Boolean) : void
        {
            EventUtil.addNetEvent(ServerCommand.SingleTowerCopyGetFtRwInfoRes, this.onFirstRwInfoBack, param1);
            EventUtil.addNetEvent(ServerCommand.SingleTowerCopyGetFtRes, this.onGetRwInfoBack, param1);
            EventUtil.addNetEvent(ServerCommand.CopyEnterTimesUpdate, this.onUpdateDay, param1);
            return;
        }// end function

        private function initTab() : void
        {
            this._showArr = this._levelArr.slice(0, this._openLen);
            var _loc_1:* = new DataProvider(this._showArr);
            this._btnList.dataProvider = _loc_1;
            this._btnList.drawNow();
            this._btnSelIndex = 0;
            return;
        }// end function

        private function initCopysInfo() : void
        {
            var _loc_1:int = 0;
            var _loc_2:int = 0;
            _loc_2 = 0;
            while (_loc_2 < this._showArr.length)
            {
                
                _loc_1 = this._showArr[_loc_2];
                if (_loc_1 > LevelCheckUtil.curLevel)
                {
                    _loc_2 = _loc_2 - 1;
                    _loc_2 = _loc_2 < 0 ? (0) : (_loc_2);
                    break;
                }
                _loc_2++;
            }
            this._btnList.selectedIndex = _loc_2 >= this._showArr.length ? ((this._showArr.length - 1)) : (_loc_2);
            this.onBtnChange(null);
            return;
        }// end function

        private function firstOpenEnter() : void
        {
            var _loc_1:int = 1;
            this._copyList.selectedIndex = _loc_1 - 1;
            return;
        }// end function

        private function onBtnChange(event:Event) : void
        {
            var _loc_2:* = this._showArr[this._btnList.selectedIndex];
            if (_loc_2 > LevelCheckUtil.curLevel)
            {
                MsgManager.showRollTipsMsg("" + Language.getString(70956));
                this._btnList.selectedIndex = this._btnSelIndex;
                return;
            }
            this.updateByEnterLv(_loc_2, true);
            this.reqFirstRwInfo(_loc_2);
            return;
        }// end function

        private function handleCellRendererChange(event:Event) : void
        {
            return;
        }// end function

        private function updateByEnterLv(param1:int, param2:Boolean) : void
        {
            var _loc_6:Object = null;
            var _loc_3:* = CopyConfig.instance.getGroupTowerCopyByLevel(param1);
            var _loc_4:* = _loc_3[1];
            var _loc_5:* = _loc_3[0];
            var _loc_7:* = SingleTowerCopyUtil.getCanGetInLvByIndex(_loc_5.code);
            var _loc_8:* = _loc_7;
            this._pageSelecter.maxPage = Math.ceil(_loc_4.length / this._pageSize);
            if (param2)
            {
                this._pageSelecter.currentPage = _loc_8 / this._pageSize + 1;
            }
            var _loc_9:* = (this._pageSelecter.currentPage - 1) * this._pageSize;
            var _loc_10:* = this._pageSelecter.currentPage * this._pageSize > _loc_4.length ? (_loc_4.length) : (this._pageSelecter.currentPage * this._pageSize);
            var _loc_11:* = Cache.instance.role.entityInfo.level;
            var _loc_12:* = _loc_10 - _loc_9;
            var _loc_13:Array = [];
            var _loc_14:* = _loc_9;
            while (_loc_14 < _loc_10)
            {
                
                _loc_6 = {lv:(_loc_14 + 1), mapId:_loc_4[_loc_14], code:_loc_5.code, group:_loc_5.icon};
                _loc_13.push(_loc_6);
                _loc_14++;
            }
            this._copyList.dataProvider = new DataProvider(_loc_13);
            if (_loc_8 > (_loc_10 - 1))
            {
                _loc_8 = _loc_10 - 1;
            }
            _loc_8 = _loc_8 % 10;
            this._copyList.selectedIndex = _loc_8;
            this._copyList.drawNow();
            return;
        }// end function

        private function reqFirstRwInfo(param1:int) : void
        {
            var _loc_2:* = CopyConfig.instance.getGroupTowerCopyByLevel(param1);
            var _loc_3:* = _loc_2[0];
            Dispatcher.dispatchEvent(new DataEvent(EventName.SingleTowerGetFirstRwInfo, _loc_3));
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            var _loc_2:* = this._showArr[this._btnList.selectedIndex];
            this.updateByEnterLv(_loc_2, false);
            return;
        }// end function

        private function onEnterCopy(event:MouseEvent) : void
        {
            var _loc_2:* = this._copyList.getItemAt(this._copyList.selectedIndex);
            var _loc_3:* = _loc_2.lv;
            var _loc_4:* = _loc_2.code;
            var _loc_5:* = SingleTowerCopyUtil.getCanGetInLvByIndex(_loc_4);
            if (_loc_3 > (_loc_5 + 1))
            {
                MsgManager.showRollTipsMsg(Language.getString(70957) + (_loc_5 + 1));
                return;
            }
            if (true)
            {
                if (!SingleTowerCopyUtil.isEnterTimeEnogth())
                {
                    MsgManager.showRollTipsMsg("" + Language.getString(70958));
                    return;
                }
            }
            GameProxy.copy.enterTowerCopy4(_loc_4, _loc_3);
            return;
        }// end function

        private function updateEnterNum() : void
        {
            var _loc_1:* = Cache.instance.copy.groupTower.singleGanInfo.todayPassNum;
            this._curNum.text = "" + _loc_1;
            return;
        }// end function

        private function onUpdateDay(param1:Object) : void
        {
            this.updateEnterNum();
            return;
        }// end function

        private function onFirstRwInfoBack(param1:Object) : void
        {
            this.flashList();
            return;
        }// end function

        private function onGetRwInfoBack(param1:Object) : void
        {
            this.flyIcons(param1);
            this.flashList();
            return;
        }// end function

        private function flashList() : void
        {
            var _loc_1:* = this._showArr[this._btnList.selectedIndex];
            if (_loc_1 > LevelCheckUtil.curLevel)
            {
                MsgManager.showRollTipsMsg("" + Language.getString(70956));
                this._btnList.selectedIndex = this._btnSelIndex;
                return;
            }
            this.updateByEnterLv(_loc_1, false);
            return;
        }// end function

        private function flyIcons(param1:Object) : void
        {
            var _loc_3:Object = null;
            var _loc_4:SingleTowerListCell = null;
            if (this._copyList == null)
            {
                return;
            }
            var _loc_2:int = 0;
            while (_loc_2 < this._copyList.length)
            {
                
                _loc_3 = this._copyList.getItemAt(_loc_2);
                _loc_4 = this._copyList.itemToCellRenderer(_loc_3) as SingleTowerListCell;
                if (_loc_4 && _loc_4.flyIcon(param1))
                {
                    MsgManager.showRollTipsMsg("" + Language.getString(70959));
                    break;
                }
                _loc_2++;
            }
            return;
        }// end function

    }
}
